//
//  MenuLeverageTradeView.m
//  XTXOneToOne
//
//  Created by Canny on 2018/10/29.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "MenuLeverageTradeView.h"


#define WIDTH_MENU (G_SCREENWIDTH-85)

@interface MenuLeverageTradeView()

/** view */
@property (nonatomic,strong) UIView * backView;
@end

@implementation MenuLeverageTradeView

-(instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:CGRectMake(-WIDTH_MENU, 0, G_SCREENWIDTH, G_SCREENHEIGHT)];
    
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    UIView *backView = [[UIView alloc]init];
    [self addSubview:backView];
    backView.frame=CGRectMake(0, 0, G_SCREENWIDTH,G_SCREENHEIGHT);
    _backView=backView;
    backView.backgroundColor=[UIColor blackColor];
    backView.alpha=0.5;
    
    
    NSArray *array = [NSArray arrayWithObjects:@"USDT",@"BTC",@"ETH",nil];
    __weak __typeof__ (self) wself = self;

    _slideView = [MCLTMenuSlideView segmentControlViewWithFrame:CGRectMake(0, 0, WIDTH_MENU, G_SCREENHEIGHT)];
    _slideView.backgroundColor=[UIColor whiteColor];
    _slideView.normalColor = RGB(102,102,102);
    _slideView.selectedColor = MC_THEME_COLOR;
    _slideView.SlideSelectedColor=MC_THEME_COLOR;
    
    _slideView.titleArray = array;
    _slideView.selectedTitleArray = array;
    [self addSubview:_slideView];
    _slideView.block = ^(HomeBaseTabCellModel * _Nonnull model) {
        if (wself.block) {
            wself.block(model);
            [wself disMissMenu];
        }
    };
   
    
    
    UIButton * doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    doneBtn.alpha=0.5;
    [doneBtn setTitle:@"" forState:UIControlStateNormal];
    [doneBtn setTitleColor:RGB(0, 0, 0) forState:UIControlStateNormal];
    [doneBtn setFrame:CGRectMake(WIDTH_MENU, 0, 85, G_SCREENHEIGHT)];
    [doneBtn addTarget:self action:@selector(disMissMenu) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:doneBtn];
    doneBtn.tag=8001;
    doneBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    doneBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    
    UIButton * doneBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [doneBtn2 setImage:[UIImage imageNamed:@"图层-6"] forState:UIControlStateNormal];
    doneBtn2.backgroundColor=MC_TEST_COLOR;
    
    [doneBtn2 setFrame:CGRectMake(WIDTH_MENU-35, TopBackButtonHeight, 9, 16)];
    [doneBtn2 addTarget:self action:@selector(disMissMenu) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:doneBtn2];
    
    
   
    
}

#pragma mark-快速创建
+(instancetype)InitPopMenuLeverageTradeView{
    return [[self alloc]initWithFrame:CGRectZero ];
}



#pragma mark-弹出
- (void)show
{
    [self showInView:[UIApplication sharedApplication].keyWindow];
}

#pragma mark-添加弹出移除的动画效果
- (void)showInView:(UIView *)view
{

    // 浮现
    [UIView animateWithDuration:0.3 animations:^{

        
        self.frame = CGRectMake(0, 0, G_SCREENWIDTH, G_SCREENHEIGHT);
        
        
    } completion:^(BOOL finished) {
        
//        self.backView.backgroundColor=RGB(0, 0, 0);
//        self.backView.alpha=0.5;
        
    }];
    
    [view addSubview:self];

    
}


-(void)disMissMenu{

#pragma mark-点击取消
    
    [UIView animateWithDuration:0.3 animations:^{
        
        self.alpha = 0;
        
        self.frame = CGRectMake(-WIDTH_MENU, 0, G_SCREENWIDTH, G_SCREENHEIGHT);

    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}


@end











